debugger;

canvas = document.createElement('canvas');
ctx = canvas.getContext('2d');
document.body.appendChild(canvas);
canvas.height = 400;
canvas.width = 1000;



function renderToCanvas(width, height, renderFunction, aState) {
    buffer = document.createElement('canvas');
    buffer.width = width;
    buffer.height = height;
    renderFunction(buffer.getContext('2d'), aState);
    return buffer;
}

function loop() {
	cached = renderToCanvas(canvas.width, canvas.height, Render, anim);
	ctx.drawImage(cached, 0, 0);
	//Render(a);
	//ctx.drawImage(buffer, 0,0);
	requestAnimFrame(loop);
	
}

function Init() {
	window.addEventListener('keydown', keyDown, false);
	window.addEventListener('keyup', keyUp, false);
	process();
	loop();
}

Init();
